package com.example.test.controller;

import com.example.test.entity.User;
import com.example.test.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/user")
public class UserController {
    @Autowired
    private IUserService iLoginService;

    @RequestMapping(value = "/login", method = RequestMethod.POST)
    private User login(@RequestBody User user){
        return iLoginService.login(user.getUsername(), user.getPassword());
    }

    @RequestMapping(value = "/param", method = RequestMethod.POST)
    private void param(@RequestParam String s){
        System.out.println(s);
    }

    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    private void insert(@RequestBody User user){
        iLoginService.insert(user.getUsername(), user.getPassword());
    }

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    private void update(@RequestBody User user){
        iLoginService.update(user.getUsername(), user.getPassword());
    }

    @RequestMapping(value = "/check", method = RequestMethod.POST)
    private int check(@RequestParam String username){
        if(iLoginService.check(username).size()>0)
            return 1;
        else
            return 0;
    }
}
